from python_baway.review.review_2021_02_18Thu.birthdays.xrandom_names_and_birthdays import xget_persons_names_and_birthdays
import datetime
import random
import pickle
from python_baway.common.xcommon import xshow_table, sep

try:
    # raise ValueError()
    xfile = open('xbirthdays5_file.tmp.dat', 'rb')
    xdata = pickle.load(xfile)
    xfile.close()
    sep('Data from file')
    xis_need_write = False
except:
    random.seed(4)
    xdata = xget_persons_names_and_birthdays(3, 2, datetime.datetime(1990, 1, 1, 0, 0, 0))
    sep('Data from random')
    xis_need_write = True

xshow_table(xdata)

if xis_need_write:
    xfile = open('xbirthdays5_file.tmp.dat', 'wb')
    pickle.dump(xdata, xfile)
    xfile.close()
